package com.itheima.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import com.itheima.health.utils.resources.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController   //  @Controller +@ResponseBody
@Api(tags = "检查组管理")
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;


    @PostMapping("ordersetting/importOrderSettings")
    @ApiOperation(value = "文件excel解析",notes = "批量上传数据")
       public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file){
        try {
            List<String[]> ordersettinglist = POIUtils.readExcel(file);
            //   string[0]----  第一列   日期    String[1]   第二列值   最大预约数
            orderSettingService.saveOrderSettingBatch(ordersettinglist);
            return  new Result(true, MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }
    }
 @PutMapping("ordersetting/updateNumberByOrderDate/{orderdate}/{number}")
       public Result updateNumberByOrderDate(@PathVariable("orderdate") String orderdate , @PathVariable("number") int number){
        try {
              orderSettingService.updateNumberByOrderDate(orderdate,number);
            return  new Result(true, MessageConstant.EDIT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.EDIT_ORDERSETTING_FAIL);
        }
    }

     @GetMapping("ordersetting/findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable("year") int year,@PathVariable("month") int month){
        try {
           Map map =  orderSettingService.findSettingData(year,month);
            return  new Result(true, MessageConstant.QUERY_ORDERSETTING_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, MessageConstant.QUERY_ORDERSETTING_FAIL);
        }
    }



}
